package com.cykj.faceledtv.data.db;

import android.content.Context;

import com.cykj.faceledtv.data.db.model.DaoMaster;
import com.cykj.faceledtv.data.db.model.UserDataDao;
import com.cykj.faceledtv.di.ApplicationContext;
import com.cykj.faceledtv.di.DatabaseInfo;

import org.greenrobot.greendao.database.Database;

import javax.inject.Inject;

/**
 * 数据库升级操作类
 *
 * @author jzh
 * @date 2018/12/11 17:30
 */

public class DbOpenHelper extends DaoMaster.OpenHelper {
    @Inject
    public DbOpenHelper(@ApplicationContext Context context, @DatabaseInfo String name) {
        super(context, name);
    }

    @Override
    public void onUpgrade(Database db, int oldVersion, int newVersion) {
        super.onUpgrade(db, oldVersion, newVersion);
        /*
        在这里进行数据库升级后的操作
         */
        MigrationHelper.migrate(db, new MigrationHelper.ReCreateAllTableListener() {

            @Override
            public void onCreateAllTables(Database db, boolean ifNotExists) {
                DaoMaster.createAllTables(db, ifNotExists);
            }

            @Override
            public void onDropAllTables(Database db, boolean ifExists) {
                DaoMaster.dropAllTables(db, ifExists);
            }
        }, UserDataDao.class);
    }
}
